package com.zbc.zbcservice.controller;

import com.zbc.zbcservice.pojo.Category;
import com.zbc.zbcservice.service.ManageCategoryService;
import com.zbc.zbcservice.vo.JasonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/category")
public class ManageCategoryController {

    @Autowired
    private ManageCategoryService manageCategoryService;


    @GetMapping("/findCategoryList")
    public JasonResult findCategoryList() {

        List<Category> data = manageCategoryService.findCategoryList();

        return JasonResult.success(data);
    }
    //根据ID修改状态信息
    @PutMapping("/status/{id}/{status}")
    public JasonResult updateStatus(Category category) {
        System.out.println("abd");
        manageCategoryService.updateStatus(category);
        return JasonResult.success("更新成功!");
    }

    @GetMapping("/ParentCategoryList/{parentId}")
    public JasonResult ParentCategoryList(Integer parentId){
        List<Category> parentIdList = manageCategoryService.ParentCategoryList(parentId);
        return JasonResult.success(parentIdList);
    }


    @PostMapping("/saveCategory")
    public JasonResult addCategoryForm(@RequestBody Category category){
        manageCategoryService.addCategoryForm(category);
        return JasonResult.success();
    }

    @PutMapping("/updateCategory")
    public JasonResult updateCategory(@RequestBody Category category){
        manageCategoryService.updateCategory(category);
        return JasonResult.success();
    }


}
